/**
 * There are arthur code generation
 */
package	com.arthur.shopping.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.entity.Example;

import com.arthur.common.service.impl.BaseService;
import com.arthur.shopping.dao.TypeGoodsMapper;
import com.arthur.shopping.domain.TypeGoods;
import com.arthur.shopping.service.TypeGoodsService;

@Service("typeGoodsService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TypeGoodsServiceImpl extends BaseService<TypeGoods> implements TypeGoodsService {

	@Autowired
	private TypeGoodsMapper typeGoodsMapper;
	
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void deletes(String ids) {
		List<String> list = Arrays.asList(ids.split(","));
		this.batchDelete(list, "id", TypeGoods.class);
	}


	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void deletes(List<TypeGoods> list) {
		for (TypeGoods typeGoods : list) {
			this.typeGoodsMapper.delete(typeGoods);
		}
	}


	@Override
	public String selectGoodsTypeIdStr(Long goodId) {
		Example example = new Example(TypeGoods.class);
		example.createCriteria().andCondition("goodsId=", goodId);
		List<TypeGoods> list = this.selectByExample(example);
		
		StringBuilder bf = new StringBuilder("");
		for (TypeGoods typeGoods : list) {
			bf.append(typeGoods.getTypeid()).append(",");
		}
		
		if(!bf.toString().equals("")){
			return bf.substring(0, bf.length()-1);
		}
		
		return bf.toString();
	}
}
